{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "35cd53a4-4e12-40e4-935e-c8a5787253e7",
   "metadata": {},
   "source": [
    "## Lab\n",
    "\n",
    "读取 【iris 数据集】（`iris_dataset.csv`） 中的花萼长度（第一列）数据，对其进行排序、去重、求和、累积和、均值、方差、标准差、最大值、最小值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "dd6b75fa-0ded-4bb9-8e8a-61bb7bd221ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bc19d47d-886a-4afe-a8d7-10d7ae64b629",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(150, 4)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = np.loadtxt('iris_dataset.csv', delimiter=',')\n",
    "data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "db41c0d9-5738-446f-b00b-e3092f7777e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "col1 = data[:, 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "eb411f34-29b0-4c07-b20d-e32522fb362b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5.1, 4.9, 4.7, 4.6, 5. , 5.4, 4.6, 5. , 4.4, 4.9, 5.4, 4.8, 4.8,\n",
       "       4.3, 5.8, 5.7, 5.4, 5.1, 5.7, 5.1, 5.4, 5.1, 4.6, 5.1, 4.8, 5. ,\n",
       "       5. , 5.2, 5.2, 4.7, 4.8, 5.4, 5.2, 5.5, 4.9, 5. , 5.5, 4.9, 4.4,\n",
       "       5.1, 5. , 4.5, 4.4, 5. , 5.1, 4.8, 5.1, 4.6, 5.3, 5. , 7. , 6.4,\n",
       "       6.9, 5.5, 6.5, 5.7, 6.3, 4.9, 6.6, 5.2, 5. , 5.9, 6. , 6.1, 5.6,\n",
       "       6.7, 5.6, 5.8, 6.2, 5.6, 5.9, 6.1, 6.3, 6.1, 6.4, 6.6, 6.8, 6.7,\n",
       "       6. , 5.7, 5.5, 5.5, 5.8, 6. , 5.4, 6. , 6.7, 6.3, 5.6, 5.5, 5.5,\n",
       "       6.1, 5.8, 5. , 5.6, 5.7, 5.7, 6.2, 5.1, 5.7, 6.3, 5.8, 7.1, 6.3,\n",
       "       6.5, 7.6, 4.9, 7.3, 6.7, 7.2, 6.5, 6.4, 6.8, 5.7, 5.8, 6.4, 6.5,\n",
       "       7.7, 7.7, 6. , 6.9, 5.6, 7.7, 6.3, 6.7, 7.2, 6.2, 6.1, 6.4, 7.2,\n",
       "       7.4, 7.9, 6.4, 6.3, 6.1, 7.7, 6.3, 6.4, 6. , 6.9, 6.7, 6.9, 5.8,\n",
       "       6.8, 6.7, 6.7, 6.3, 6.5, 6.2, 5.9])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "col1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f1fa8788-01c6-48c0-a0e6-8002b2f79898",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4.3, 4.4, 4.4, 4.4, 4.5, 4.6, 4.6, 4.6, 4.6, 4.7, 4.7, 4.8, 4.8,\n",
       "       4.8, 4.8, 4.8, 4.9, 4.9, 4.9, 4.9, 4.9, 4.9, 5. , 5. , 5. , 5. ,\n",
       "       5. , 5. , 5. , 5. , 5. , 5. , 5.1, 5.1, 5.1, 5.1, 5.1, 5.1, 5.1,\n",
       "       5.1, 5.1, 5.2, 5.2, 5.2, 5.2, 5.3, 5.4, 5.4, 5.4, 5.4, 5.4, 5.4,\n",
       "       5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6,\n",
       "       5.7, 5.7, 5.7, 5.7, 5.7, 5.7, 5.7, 5.7, 5.8, 5.8, 5.8, 5.8, 5.8,\n",
       "       5.8, 5.8, 5.9, 5.9, 5.9, 6. , 6. , 6. , 6. , 6. , 6. , 6.1, 6.1,\n",
       "       6.1, 6.1, 6.1, 6.1, 6.2, 6.2, 6.2, 6.2, 6.3, 6.3, 6.3, 6.3, 6.3,\n",
       "       6.3, 6.3, 6.3, 6.3, 6.4, 6.4, 6.4, 6.4, 6.4, 6.4, 6.4, 6.5, 6.5,\n",
       "       6.5, 6.5, 6.5, 6.6, 6.6, 6.7, 6.7, 6.7, 6.7, 6.7, 6.7, 6.7, 6.7,\n",
       "       6.8, 6.8, 6.8, 6.9, 6.9, 6.9, 6.9, 7. , 7.1, 7.2, 7.2, 7.2, 7.3,\n",
       "       7.4, 7.6, 7.7, 7.7, 7.7, 7.7, 7.9])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#排序\n",
    "col1[col1.argsort()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d155d293-7a38-4391-a7db-dc5954e505fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5. , 5.1, 5.2, 5.3, 5.4, 5.5,\n",
       "       5.6, 5.7, 5.8, 5.9, 6. , 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8,\n",
       "       6.9, 7. , 7.1, 7.2, 7.3, 7.4, 7.6, 7.7, 7.9])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#去重\n",
    "np.unique(col1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e9cfca66-f7bb-4112-a4fd-965e7ab1e45d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "876.5"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求和\n",
    "np.sum(col1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0559226a-7591-489d-a435-2d455d48a35b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  5.1,  10. ,  14.7,  19.3,  24.3,  29.7,  34.3,  39.3,  43.7,\n",
       "        48.6,  54. ,  58.8,  63.6,  67.9,  73.7,  79.4,  84.8,  89.9,\n",
       "        95.6, 100.7, 106.1, 111.2, 115.8, 120.9, 125.7, 130.7, 135.7,\n",
       "       140.9, 146.1, 150.8, 155.6, 161. , 166.2, 171.7, 176.6, 181.6,\n",
       "       187.1, 192. , 196.4, 201.5, 206.5, 211. , 215.4, 220.4, 225.5,\n",
       "       230.3, 235.4, 240. , 245.3, 250.3, 257.3, 263.7, 270.6, 276.1,\n",
       "       282.6, 288.3, 294.6, 299.5, 306.1, 311.3, 316.3, 322.2, 328.2,\n",
       "       334.3, 339.9, 346.6, 352.2, 358. , 364.2, 369.8, 375.7, 381.8,\n",
       "       388.1, 394.2, 400.6, 407.2, 414. , 420.7, 426.7, 432.4, 437.9,\n",
       "       443.4, 449.2, 455.2, 460.6, 466.6, 473.3, 479.6, 485.2, 490.7,\n",
       "       496.2, 502.3, 508.1, 513.1, 518.7, 524.4, 530.1, 536.3, 541.4,\n",
       "       547.1, 553.4, 559.2, 566.3, 572.6, 579.1, 586.7, 591.6, 598.9,\n",
       "       605.6, 612.8, 619.3, 625.7, 632.5, 638.2, 644. , 650.4, 656.9,\n",
       "       664.6, 672.3, 678.3, 685.2, 690.8, 698.5, 704.8, 711.5, 718.7,\n",
       "       724.9, 731. , 737.4, 744.6, 752. , 759.9, 766.3, 772.6, 778.7,\n",
       "       786.4, 792.7, 799.1, 805.1, 812. , 818.7, 825.6, 831.4, 838.2,\n",
       "       844.9, 851.6, 857.9, 864.4, 870.6, 876.5])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#累积和\n",
    "col1.cumsum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ee999100-5bea-4e21-aa32-60f3774a949d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.843333333333334"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#均值\n",
    "np.mean(col1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5d181941-9826-49e9-ad0e-910c3abfe8a9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7.9"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#最大值\n",
    "col1.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0890372b-e9f2-46c7-a340-f1f9021e5c93",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.3"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#最小值\n",
    "col1.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4b3e6163-4649-4535-bcef-8f01ae53c117",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6811222222222223"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#方差\n",
    "col1.var()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "b2ce0f94-752c-4b41-826f-d976f56f09b4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8253012917851409"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#标准差\n",
    "col1.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3be705f5-cadb-4e13-8e9a-08be204457f6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
